Test Series - java script

Test Number 8/92

Q: The unordered collection of properties, each of which has a name and a value is called _________
A. String
B. Object
C. Serialized Object
D. Array
Solution: Objects in JavaScript may be defined as an unordered collection of related data, of primitive or reference types, in the form of “key:value” pairs. Hence each of the property has a name and value.
Q: A linkage of series of prototype objects is called as ________
A. prototype stack
B. prototype chain
C. prototype class
D. prototypes
Solution: Consider an example, Date.prototype inherits properties from Object.prototype, so a Date object created by new Date() inherits properties from both Date.prototype and Object.prototype. This linked series of prototype objects is known as prototype chain.
Q: The object has three object attributes namely ________
A. Class, parameters, object’s extensible flag
B. Prototype, class, objects’ parameters
C. Prototype, class, object’s extensible flag
D. Native object, Classes and Interfaces and Object’s extensible flag
Solution: Every object has three associated object attributes:
An object’s prototype is a reference to another object from which properties are inherited.
An object’s class is a string that categorizes the type of an object.
An object’s extensible flag specifies whether new properties may be added to the object.
Q: In the following syntax, the data type within the square brackets must be ___________

book[datatype]=assignment_value;
A. An integer
B. A String
C. An object
D. Floating point
Solution: The value inside the square bracket is used to access that data element or the property of the object. When using square bracket notation, the expression inside the square brackets must evaluate to a string or a value that can be converted to a string.
Q: To determine whether one object is the prototype of (or is part of the prototype chain of) another object, one should use the ____________
A. isPrototypeOf() method
B. equals() method
C. === operator
D. ==opertor
Solution: Prototype is a global property which is available with almost all the objects. To determine whether one object is the prototype of (or is part of the prototype chain of) another object, one should use the isPrototype() method. To find out if p is the prototype of o write p.isPrototypeOf(o).
Q: What is the prototype represents in the following JavaScript code snippet?

function f() {};
A. Function f
B. A custom constructor
C. Prototype of a function
D. Not valid
Solution: All object instances have a constructor property that point to the constructor function that created it. A custom constructor is a constructor which requires no arguments and is created automatically by the compiler at the time of object creation if not created by the user.
Q: The purpose of extensible attribute is to __________
A. make all of the own properties of that object non configurable
B. to configure and bring a writable property
C. “lock down” objects into a known state and prevent outside tampering
D. to include new properties into the object
Solution: Extensible attributes determines whether the object can have new properties or not. Therefore extensible attribute will allow an object to include and write properties into them.
Q: The basic purpose of the toLocaleString() is to _________
A. return a localised object representation
B. return a parsed string
C. return a local time in the string format
D. return a localized string representation of the object
Solution: .toLocaleString is a predefined function in javascript which is used to return a localized string representation of the object. For example the date.toLocaleString() is an inbuilt function in JavaScript which is used to convert a date and time to a string.
Q: What will be the output of the following JavaScript code?

const obj = {prop: 12};  
Object.preventExtensions(obj);  
console.log( Object.isExtensible(obj));
A. 12
B. true
C. false
D. error
Solution: The Object.preventExtensions() only prevents the addition of new properties from ever being added to an object. This change is a permanent that means once an object has been made non-extensible, it cannot be made extensible again.
Q: What will be the output of the following JavaScript code?

const object1 = {  
  property1: 20
};  
console.log(Object.is(object1));
A. 20
B. true
C. false
D. error
Solution: The Object.is() method of JavaScript is used to determine whether two values are the same value. There is a special built-in method that compares values. This method returns a Boolean indicating whether or not the two arguments are the same value.

You Have Score    /10